//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.bfsuol.bfsuolcomponents.log.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bfsuol.bfsuolcomponents.log.service.SysLogService;
import com.bfsuol.bfsuolframework.core.controller.SpringControllerSupport;
import com.bfsuol.bfsuolframework.core.controller.json.MessageJson;
import com.bfsuol.bfsuolframework.core.controller.support.Pagination;
import com.bfsuol.bfsuolframework.core.controller.support.QueryParam;
import com.bfsuol.bfsuolframework.core.exception.ValidationException;
import com.bfsuol.bfsuolframework.core.spring.QueryParameter;
import com.bfsuol.bfsuolframework.security.annotations.SecDelete;
import com.bfsuol.bfsuolframework.security.annotations.SecList;
import com.bfsuol.bfsuolframework.security.annotations.SecPrivilege;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"/components/log"})
public class SysLogController extends SpringControllerSupport {

    @Autowired
    private SysLogService sysLogService;

    @SecPrivilege(
            title = "日志管理"
    )
    @RequestMapping({"/index"})
    public ModelAndView index(Model model) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName(this.getViewNamedPath("index"));
        return modelAndView;
    }

    @SecList
    @ApiOperation(value = "日志管理列表",httpMethod = "GET")
    @RequestMapping("/list")
    public ModelAndView list(
            @QueryParameter("query") QueryParam query,
            @ModelAttribute("page") Pagination page, Model model){

        com.baomidou.mybatisplus.extension.plugins.pagination.Page page1 = new Page(page.getDefaultCurrentPage(),page.getPageSize());
        com.baomidou.mybatisplus.extension.plugins.pagination.Page logPages = sysLogService.page(page1,new QueryWrapper<>());
        page.setItems(logPages.getRecords());
        page.setTotalRecord((int) logPages.getTotal());

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName(getViewNamedPath("list"));
        return modelAndView;
    }

    @SecDelete
    @RequestMapping({"/delete/{id}"})
    @ResponseBody
    public MessageJson delete(@PathVariable("id") Long id) {
        this.sysLogService.removeById(id);
        return MessageJson.success(new Object[]{"成功删除1条"});
    }

    @SecDelete
    @RequestMapping({"/delete"})
    @ResponseBody
    public MessageJson delete(@RequestParam("ids") Long[] ids) {
        if(ids != null && ids.length != 0) {
            Long[] var5 = ids;
            int var4 = ids.length;

            for(int var3 = 0; var3 < var4; ++var3) {
                Long id = var5[var3];
                this.sysLogService.removeById(id);
            }

            return MessageJson.success(new Object[]{"成功删除" + ids.length + "条"});
        } else {
            throw new ValidationException("未删除");
        }
    }
}
